package com.jdew.thkj.activity;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.RelativeSizeSpan;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.request.RequestOptions;
import com.jdew.thkj.R;
import com.jdew.thkj.base.BaseActivity;
import com.jdew.thkj.base.BaseFragment;
import com.jdew.thkj.bean.LiangHaoBean;
import com.jdew.thkj.fragment.FragmentFactory;
import com.jdew.thkj.manager.AppConfig;
import com.jdew.thkj.network.RetrofitManager;
import com.jdew.thkj.network.api.RequestApi;
import com.jdew.thkj.utils.MD5Utils;
import com.jdew.thkj.utils.RegexValidateUtils;
import com.jdew.thkj.utils.ToastUtils;
import com.jdew.thkj.utils.WeiboDialogUtils;
import com.jdew.thkj.view.CircleImageView;
import com.jdew.thkj.view.GlideCircleTransform;

import org.greenrobot.eventbus.EventBus;

import java.text.DecimalFormat;
import java.util.HashMap;

import butterknife.Bind;
import butterknife.ButterKnife;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

import static com.bumptech.glide.request.RequestOptions.bitmapTransform;

/**
 * Created by yangzai on 2018/3/27 0027.
 */

public class BaoBiaoActivity extends BaseActivity {

    @Bind(R.id.back)
    ImageView back;
    @Bind(R.id.title)
    TextView title;
    @Bind(R.id.themonth)
    TextView themonth;
    @Bind(R.id.lastmonth)
    TextView lastmonth;
    @Bind(R.id.lastyg)
    TextView lastyg;
    @Bind(R.id.ketixian)
    TextView ketixian;
    @Bind(R.id.tixian)
    TextView tixian;
    @Bind(R.id.mingxi)
    LinearLayout mingxi;
    @Bind(R.id.right)
    TextView right;
    @Bind(R.id.tab)
    TabLayout tablayout;
    @Bind(R.id.th_viewpager)
    ViewPager viewpager;
    @Bind(R.id.more)
    TextView more;
    @Bind(R.id.tb)
    TextView tb;
    @Bind(R.id.pdd)
    TextView pdd;
    @Bind(R.id.lastmonth_yg)
    TextView lastmonthYg;
    @Bind(R.id.line1)
    View line1;
    @Bind(R.id.line2)
    View line2;
    @Bind(R.id.jd)
    TextView jd;
    @Bind(R.id.line3)
    View line3;
    @Bind(R.id.logo)
    CircleImageView logo;
    @Bind(R.id.name)
    TextView name;
    @Bind(R.id.level)
    ImageView level;
    @Bind(R.id.regist_ma)
    TextView registMa;
    @Bind(R.id.fuzhi)
    TextView fuzhi;
    @Bind(R.id.inviter_view)
    LinearLayout inviterView;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.jiner)
    TextView jiner;
    @Bind(R.id.tg)
    TextView tg;
    private ViewHolder holder;
    public String[] mTilte = null;
    private DecimalFormat df = new DecimalFormat("0.00");
    private Dialog mWeiboDialog;
    public int type = 0;

    @Override
    public int bindLayout() {
        return R.layout.activity_baobiao;
    }

    @Override
    public void initView(View view) {
        title.setText("订单报表");
        back.setVisibility(View.VISIBLE);
        right.setVisibility(View.VISIBLE);
        right.setText("提现记录");
        line1.setVisibility(View.VISIBLE);
        tixian.setOnClickListener(this);
        back.setOnClickListener(this);
        right.setOnClickListener(this);
        mingxi.setOnClickListener(this);
        more.setOnClickListener(this);
        tb.setOnClickListener(this);
        pdd.setOnClickListener(this);
        jd.setOnClickListener(this);
        fuzhi.setOnClickListener(this);
        tg.setOnClickListener(this);
        ShortPagerAdapter adapter = new ShortPagerAdapter(getSupportFragmentManager());
        viewpager.setAdapter(adapter);
        tablayout.setupWithViewPager(viewpager);
        //tab选中的监听事件
        tablayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                holder = new ViewHolder(tab.getCustomView());
                holder.tvTabName.setSelected(true);
                //选中后字体变大
                holder.tvTabName.setTextSize(18);
                holder.tvTabName.setTextColor(getResources().getColor(R.color.color_pink));
                holder.tvTabName.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);
                //让Viewpager跟随TabLayout的标签切换
                viewpager.setCurrentItem(tab.getPosition());

            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                holder = new ViewHolder(tab.getCustomView());
                holder.tvTabName.setSelected(false);
                holder.tvTabName.setTextColor(getResources().getColor(R.color.tabBackground));
                //恢复为默认字体大小
                holder.tvTabName.setTextSize(14);
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
        setTabView();
    }

    private void setTabView() {
        holder = null;
        for (int i = 0; i < mTilte.length; i++) {
            //依次获取标签
            TabLayout.Tab tab = tablayout.getTabAt(i);
            //为每个标签设置布局
            tab.setCustomView(R.layout.tab_item);
            holder = new ViewHolder(tab.getCustomView());
            //为标签填充数据
            holder.tvTabName.setText(mTilte[i]);
            //默认选择第一项
            if (i == 0) {
                holder.tvTabName.setSelected(true);
                holder.tvTabName.setTextColor(getResources().getColor(R.color.color_pink));
                holder.tvTabName.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);
                holder.tvTabName.setTextSize(18);
            }
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tixian: {
                startActivity(TiXianActivity.class);
            }
            break;
            case R.id.back: {
                finish();
            }
            break;
            case R.id.right: {
                startActivity(TiXianDetailActivity.class);
            }
            break;
            case R.id.mingxi: {
                startActivity(OrderMingXiActivity.class);
            }
            break;
            case R.id.more: {
                startActivity(CommissionsActivity.class);
            }
            break;
            case R.id.tg: {
                startActivity(DetailsOfBeautifulNumberAwardsActivity.class);
            }
            break;
            case R.id.fuzhi: {
                RegexValidateUtils.copyText(this, registMa.getText().toString());
                ToastUtils.getInstance(this).showMessage("复制成功!");
            }
            break;
            case R.id.tb: {
                type = 0;
                line1.setVisibility(View.VISIBLE);
                line2.setVisibility(View.GONE);
                line3.setVisibility(View.GONE);
                tb.setTextColor(getResources().getColor(R.color.theme_color));
                pdd.setTextColor(getResources().getColor(R.color.color_000000));
                jd.setTextColor(getResources().getColor(R.color.color_000000));
                EventBus.getDefault().post("tb");
                GetThisMonthMoney(type);
                GetLastMonthMoney(type);
                GetLastMontYghMoney(type);
            }
            break;
            case R.id.pdd: {
                type = 1;
                line1.setVisibility(View.GONE);
                line2.setVisibility(View.VISIBLE);
                line3.setVisibility(View.GONE);
                tb.setTextColor(getResources().getColor(R.color.color_000000));
                pdd.setTextColor(getResources().getColor(R.color.theme_color));
                jd.setTextColor(getResources().getColor(R.color.color_000000));
                EventBus.getDefault().post("pdd");
                GetPDDLastMonthMoneyYG(type);
                GetPDDLastMonthMoney(type);
                GetPDDThisMonthMoney(type);
            }
            break;
            case R.id.jd: {
                type = 4;
                line1.setVisibility(View.GONE);
                line2.setVisibility(View.GONE);
                line3.setVisibility(View.VISIBLE);
                tb.setTextColor(getResources().getColor(R.color.color_000000));
                pdd.setTextColor(getResources().getColor(R.color.color_000000));
                jd.setTextColor(getResources().getColor(R.color.theme_color));
                EventBus.getDefault().post("jd");
                GetJDhMoney(type, "ThisMonth");
                GetJDhMoney(type, "LastMonth");
                GetJDhMoney(type, "Settlement");
            }
            break;
            default:
                break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        sp = getSharedPreferences("user", Activity.MODE_PRIVATE);
        editor = sp.edit();
        registMa.setText(sp.getString("newUserCode", ""));
        String photoPath = sp.getString("UserImgUrl", "");
        if (photoPath.equals("")) {
            logo.setImageResource((R.mipmap.default_icon));
        } else {
            RequestOptions options = new RequestOptions().priority(Priority.HIGH);
            Glide.with(this).load(photoPath).apply(options).apply(bitmapTransform(new GlideCircleTransform(this))).into(logo);
        }
        name.setText("欢迎您:" + sp.getString("userPhone", ""));
        GetLevel();
        GetThisMonthMoney(type);
        GetLastMonthMoney(type);
        GetLastMontYghMoney(type);
        GetPDDThisMonthMoney(type);
        GetPDDLastMonthMoneyYG(type);
        GetPDDLastMonthMoney(type);
        GetJDhMoney(type, "ThisMonth");
        GetJDhMoney(type, "LastMonth");
        GetJDhMoney(type, "Settlement");
        GetBonusSum();
    }

    public void GetLevel() {
        String timesamp = RegexValidateUtils.getTime13();
        String numsamp = RegexValidateUtils.getRandom10();
        RetrofitManager.getInstance(AppConfig.BASE_URL).createReq(RequestApi.class).GetLevel(sp.getString("userPhone", ""), RegexValidateUtils.getUniquePsuedoID(), timesamp, numsamp, MD5Utils.getMD5(RegexValidateUtils.ASCIISort(timesamp + numsamp + RegexValidateUtils.getUniquePsuedoID() + sp.getString("SignToken", "") + "UserPhone" + sp.getString("userPhone", ""))).toUpperCase()).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Subscriber<JSONObject>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                Log.e("sssssssssssssss", e.toString());
            }

            @Override
            public void onNext(JSONObject json) {
                if (json.getString("code").equals("0")) {
                    more.setVisibility(View.VISIBLE);
                } else {
                    more.setVisibility(View.GONE);
                }
                if (json.getString("message").equals("铜牌教练")) {
                    level.setImageResource(R.mipmap.lv4);
                } else if (json.getString("message").equals("银牌教练")) {
                    level.setImageResource(R.mipmap.lv5);
                } else if (json.getString("message").equals("分公司")) {
                    level.setImageResource(R.mipmap.lv6);
                } else if (json.getString("message").equals("股东")) {
                    level.setImageResource(R.mipmap.lv7);
                } else if (json.getString("message").equals("超级教练")) {
                    level.setImageResource(R.mipmap.lv3);
                } else if (json.getString("message").equals("普通惠员")) {
                    level.setImageResource(R.mipmap.lv1);
                } else if (json.getString("message").equals("高级惠员")) {
                    level.setImageResource(R.mipmap.lv2);
                } else if (json.getString("message").equals("预备子公司")) {
                    level.setImageResource(R.mipmap.lv8);
                }
            }
        });
    }

    public void GetThisMonthMoney(int type) {
        if (type != 0) {
            return;
        }
        String timesamp = RegexValidateUtils.getTime13();
        String numsamp = RegexValidateUtils.getRandom10();
        RetrofitManager.getInstance(AppConfig.BASE_URL).createReq(RequestApi.class).GetThisMonthMoney(sp.getString("mpid", ""), RegexValidateUtils.getUniquePsuedoID(), timesamp, numsamp, MD5Utils.getMD5(RegexValidateUtils.ASCIISort(timesamp + numsamp + RegexValidateUtils.getUniquePsuedoID() + sp.getString("SignToken", "") + "Pid" + sp.getString("mpid", ""))).toUpperCase()).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Subscriber<JSONObject>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                Log.e("sssssssssss", e.toString());
            }

            @Override
            public void onNext(JSONObject json) {
                if (json.getString("code").equals("0")) {
                    themonth.setText("¥ " + df.format(Double.parseDouble(json.getString("data"))));
                } else if (json.getString("code").equals("-1")) {
                    themonth.setText("¥ 0.00");
                }
                SpannableString spannableString = new SpannableString(themonth.getText().toString());
                RelativeSizeSpan sizeSpan = new RelativeSizeSpan(1.2f);
                spannableString.setSpan(sizeSpan, 1, themonth.getText().toString().indexOf("."), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                themonth.setText(spannableString);
            }
        });
    }

    public void GetLastMonthMoney(int type) {
        //上月结算收益收益，可提现
        if (type != 0) {
            return;
        }
        String timesamp = RegexValidateUtils.getTime13();
        String numsamp = RegexValidateUtils.getRandom10();
        RetrofitManager.getInstance(AppConfig.BASE_URL).createReq(RequestApi.class).GetLastMonthMoney(sp.getString("mpid", ""), sp.getString("userPhone", ""), RegexValidateUtils.getUniquePsuedoID(), timesamp, numsamp, MD5Utils.getMD5(RegexValidateUtils.ASCIISort(timesamp + numsamp + RegexValidateUtils.getUniquePsuedoID() + sp.getString("SignToken", "") + "Pid" + sp.getString("mpid", "") + "phone" + sp.getString("userPhone", ""))).toUpperCase()).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Subscriber<JSONObject>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
            }

            @Override
            public void onNext(JSONObject json) {
                if (json.getString("code").equals("0")) {
                    lastmonth.setText("¥ " + df.format(Double.parseDouble(json.getString("data"))));
                    ketixian.setText(json.getString("message").equals("0") ? "¥ 0.00" : "¥ " + json.getString("message"));
                } else if (json.getString("code").equals("-2")) {
                    lastmonth.setText("¥ 0.00");
                    ketixian.setText("¥ " + json.getString("message"));
                } else if (json.getString("code").equals("-1")) {
                    lastmonth.setText("¥ 0.00");
                    ketixian.setText("¥ " + json.getString("message"));
                }
                SpannableString spannableString = new SpannableString(ketixian.getText().toString());
                SpannableString spannableString1 = new SpannableString(lastmonth.getText().toString());
                RelativeSizeSpan sizeSpan = new RelativeSizeSpan(1.2f);
                spannableString1.setSpan(sizeSpan, 1, lastmonth.getText().toString().indexOf("."), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                lastmonth.setText(spannableString1);
                spannableString.setSpan(sizeSpan, 1, ketixian.getText().toString().indexOf("."), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                ketixian.setText(spannableString);
            }
        });
    }

    public void GetLastMontYghMoney(int type) {
        if (type != 0) {
            return;
        }
        //上月预估收益
        if (null != mWeiboDialog) {
            mWeiboDialog.dismiss();
        }
        mWeiboDialog = WeiboDialogUtils.createLoadingDialog(this);
        String timesamp = RegexValidateUtils.getTime13();
        String numsamp = RegexValidateUtils.getRandom10();
        RetrofitManager.getInstance(AppConfig.BASE_URL).createReq(RequestApi.class).GetLastMonthMoneyYG(sp.getString("mpid", ""), RegexValidateUtils.getUniquePsuedoID(), timesamp, numsamp, MD5Utils.getMD5(RegexValidateUtils.ASCIISort(timesamp + numsamp + RegexValidateUtils.getUniquePsuedoID() + sp.getString("SignToken", "") + "Pid" + sp.getString("mpid", ""))).toUpperCase()).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Subscriber<JSONObject>() {
            @Override
            public void onCompleted() {
                WeiboDialogUtils.closeDialog(mWeiboDialog);
            }

            @Override
            public void onError(Throwable e) {
                WeiboDialogUtils.closeDialog(mWeiboDialog);
            }

            @Override
            public void onNext(JSONObject json) {
                WeiboDialogUtils.closeDialog(mWeiboDialog);
                if (json.getString("code").equals("0")) {
                    lastyg.setText("¥ " + df.format(Double.parseDouble(json.getString("data"))));
                } else if (json.getString("code").equals("1001")) {
                    lastyg.setVisibility(View.GONE);
                    lastmonthYg.setVisibility(View.GONE);

                }
                SpannableString spannableString = new SpannableString(lastyg.getText().toString());
                RelativeSizeSpan sizeSpan = new RelativeSizeSpan(1.2f);
                spannableString.setSpan(sizeSpan, 1, lastyg.getText().toString().indexOf("."), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                lastyg.setText(spannableString);
            }
        });
    }

    public void GetPDDThisMonthMoney(int type) {
        if (type != 1) {
            return;
        }
        String timesamp = RegexValidateUtils.getTime13();
        String numsamp = RegexValidateUtils.getRandom10();
        RetrofitManager.getInstance(AppConfig.BASE_URL).createReq(RequestApi.class).GetPDDThisMonthMoney(sp.getString("userPhone", ""), RegexValidateUtils.getUniquePsuedoID(), timesamp, numsamp, MD5Utils.getMD5(RegexValidateUtils.ASCIISort(timesamp + numsamp + RegexValidateUtils.getUniquePsuedoID() + sp.getString("SignToken", "") + "UserPhone" + sp.getString("userPhone", ""))).toUpperCase()).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Subscriber<JSONObject>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                Log.e("sssssssssss", e.toString());
            }

            @Override
            public void onNext(JSONObject json) {
                if (json.getString("code").equals("0")) {
                    themonth.setText("¥ " + df.format(Double.parseDouble(json.getString("data"))));
                } else if (json.getString("code").equals("-1")) {
                    themonth.setText("¥ 0.00");
                }
                SpannableString spannableString = new SpannableString(themonth.getText().toString());
                RelativeSizeSpan sizeSpan = new RelativeSizeSpan(1.2f);
                spannableString.setSpan(sizeSpan, 1, themonth.getText().toString().indexOf("."), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                themonth.setText(spannableString);
            }
        });
    }

    public void GetPDDLastMonthMoneyYG(int type) {
        if (type != 1) {
            return;
        }
        if (null != mWeiboDialog) {
            mWeiboDialog.dismiss();
        }
        mWeiboDialog = WeiboDialogUtils.createLoadingDialog(this);
        String timesamp = RegexValidateUtils.getTime13();
        String numsamp = RegexValidateUtils.getRandom10();
        RetrofitManager.getInstance(AppConfig.BASE_URL).createReq(RequestApi.class).GetPDDLastMonthMoneyYG(sp.getString("userPhone", ""), RegexValidateUtils.getUniquePsuedoID(), timesamp, numsamp, MD5Utils.getMD5(RegexValidateUtils.ASCIISort(timesamp + numsamp + RegexValidateUtils.getUniquePsuedoID() + sp.getString("SignToken", "") + "UserPhone" + sp.getString("userPhone", ""))).toUpperCase()).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Subscriber<JSONObject>() {
            @Override
            public void onCompleted() {
                WeiboDialogUtils.closeDialog(mWeiboDialog);
            }

            @Override
            public void onError(Throwable e) {
                WeiboDialogUtils.closeDialog(mWeiboDialog);
                Log.e("sssssssssss", e.toString());
            }

            @Override
            public void onNext(JSONObject json) {
                WeiboDialogUtils.closeDialog(mWeiboDialog);
                if (json.getString("code").equals("0")) {
                    lastyg.setText("¥ " + df.format(Double.parseDouble(json.getString("data"))));
                } else if (json.getString("code").equals("-1")) {
                    lastyg.setText("¥ 0.00");
                }
                SpannableString spannableString = new SpannableString(lastyg.getText().toString());
                RelativeSizeSpan sizeSpan = new RelativeSizeSpan(1.2f);
                spannableString.setSpan(sizeSpan, 1, lastyg.getText().toString().indexOf("."), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                lastyg.setText(spannableString);
            }
        });
    }

    public void GetPDDLastMonthMoney(int type) {
        if (type != 1) {
            return;
        }
        String timesamp = RegexValidateUtils.getTime13();
        String numsamp = RegexValidateUtils.getRandom10();
        RetrofitManager.getInstance(AppConfig.BASE_URL).createReq(RequestApi.class).GetPDDLastMonthMoney(sp.getString("userPhone", ""), RegexValidateUtils.getUniquePsuedoID(), timesamp, numsamp, MD5Utils.getMD5(RegexValidateUtils.ASCIISort(timesamp + numsamp + RegexValidateUtils.getUniquePsuedoID() + sp.getString("SignToken", "") + "UserPhone" + sp.getString("userPhone", ""))).toUpperCase()).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Subscriber<JSONObject>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                Log.e("sssssssssss", e.toString());
            }

            @Override
            public void onNext(JSONObject json) {
                if (json.getString("code").equals("0")) {
                    lastmonth.setText("¥ " + df.format(Double.parseDouble(json.getString("data"))));
                } else if (json.getString("code").equals("-1")) {
                    lastmonth.setText("¥ 0.00");
                }
                SpannableString spannableString = new SpannableString(lastmonth.getText().toString());
                RelativeSizeSpan sizeSpan = new RelativeSizeSpan(1.2f);
                spannableString.setSpan(sizeSpan, 1, lastmonth.getText().toString().indexOf("."), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                lastmonth.setText(spannableString);
            }
        });
    }

    public void GetJDhMoney(int type, final String time) {
        if (type != 4) {
            return;
        }
        String timesamp = RegexValidateUtils.getTime13();
        String numsamp = RegexValidateUtils.getRandom10();
        HashMap map = new HashMap();
        map.put("UserId", sp.getString("userId", ""));
        map.put("platForm", time);
        RetrofitManager.getInstance(AppConfig.BASE_URL).createReq(RequestApi.class).GetJdMoney(map, RegexValidateUtils.getUniquePsuedoID(), timesamp, numsamp, MD5Utils.getMD5(RegexValidateUtils.ASCIISort(timesamp + numsamp + RegexValidateUtils.getUniquePsuedoID() + sp.getString("SignToken", "") + "UserId" + sp.getString("userId", "") + "platForm" + time)).toUpperCase()).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Subscriber<JSONObject>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
                Log.e("sssssssssss", e.toString());
            }

            @Override
            public void onNext(JSONObject json) {
                if (json.getString("code").equals("0")) {
                    String result = json.getString("data");
                    JSONObject obj = JSONObject.parseObject(result);
                    if (time.equals("ThisMonth")) {
                        themonth.setText("¥ " + df.format(Double.parseDouble(obj.getString("money"))));
                    } else if (time.equals("LastMonth")) {
                        lastyg.setText("¥ " + df.format(Double.parseDouble(obj.getString("money"))));
                    } else if (time.equals("Settlement")) {
                        lastmonth.setText("¥ " + df.format(Double.parseDouble(obj.getString("money"))));
                    }
                } else if (json.getString("code").equals("-1")) {
                    lastmonth.setText("¥ 0.00");
                    themonth.setText("¥ 0.00");
                }
                SpannableString spannableString = new SpannableString(lastmonth.getText().toString());
                RelativeSizeSpan sizeSpan = new RelativeSizeSpan(1.2f);
                spannableString.setSpan(sizeSpan, 1, lastmonth.getText().toString().indexOf("."), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                lastmonth.setText(spannableString);
            }
        });

    }

    public void GetBonusSum() {
        String timesamp = RegexValidateUtils.getTime13();
        String numsamp = RegexValidateUtils.getRandom10();
        HashMap map = new HashMap();
        map.put("loginId", sp.getString("userId", ""));
        RetrofitManager.getInstance(AppConfig.BASE_URL).createReq(RequestApi.class).BonusSum(map, RegexValidateUtils.getUniquePsuedoID(), timesamp, numsamp, MD5Utils.getMD5(RegexValidateUtils.ASCIISort(timesamp + numsamp + RegexValidateUtils.getUniquePsuedoID() + sp.getString("SignToken", "") + "loginId" + sp.getString("userId", ""))).toUpperCase()).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Subscriber<JSONObject>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
                Log.e("sssssssssss", e.toString());
            }

            @Override
            public void onNext(JSONObject object) {
                if (object.getString("code").equals("0")) {
                    jiner.setText("¥ " + df.format(Double.parseDouble(object.getString("data"))));
                    SpannableString spannableString = new SpannableString(jiner.getText().toString());
                    RelativeSizeSpan sizeSpan = new RelativeSizeSpan(1.2f);
                    spannableString.setSpan(sizeSpan, 1, jiner.getText().toString().indexOf("."), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                    jiner.setText(spannableString);
                }
            }
        });

    }

    private class ShortPagerAdapter extends FragmentPagerAdapter {

        public ShortPagerAdapter(FragmentManager fm) {
            super(fm);
            mTilte = getResources().getStringArray(R.array.tab_day_Title);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTilte[position];
        }

        @Override
        public BaseFragment getItem(int position) {
            BaseFragment fragment = FragmentFactory.createFragment5(position);
            return fragment;
        }

        @Override
        public int getCount() {
            return mTilte.length;
        }
    }

    class ViewHolder {
        TextView tvTabName;

        public ViewHolder(View tabView) {
            tvTabName = (TextView) tabView.findViewById(R.id.tv_tab_name);
        }
    }
}
